package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class NewsletterDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "newsletter.db" ;
    private static final int DATABASE_VERSION = 1 ;

    public static final String TABLE_NEWSLETTER = "newsletter" ;
    public static final String NEWSLETTER_ID = "id";
    public static final String NEWSLETTER_A = "phone1";
    public static final String NEWSLETTER_B = "phone2";
    public static final String NEWSLETTER_TIME = "time";

    private static final String CREATE_TABLE_LETTER = "CREATE TABLE " + TABLE_NEWSLETTER + "(" +
            NEWSLETTER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
            NEWSLETTER_A + " TEXT NOT NULL ," +
            NEWSLETTER_B + " TEXT NOT NULL ," +
            NEWSLETTER_TIME + " TEXT )" ;


    public static final String TABLE_MESSAGE = "message" ;
    public static final String MESSAGE_SEND = "send_id" ;
    public static final String MESSAGE_RECEIVE = "receive_id" ;
    public static final String MESSAGE_TEXT = "text";
    public static final String MESSAGE_TIME = "time";

    private static final String CREATE_TABLE_MESSAGE = "CREATE TABLE " + TABLE_MESSAGE + " (" +
            MESSAGE_SEND + " TEXT ," +
            MESSAGE_RECEIVE + " TEXT ," +
            MESSAGE_TEXT + " TEXT ," +
            MESSAGE_TIME + " TEXT )";

    public NewsletterDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_LETTER);
        db.execSQL(CREATE_TABLE_MESSAGE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NEWSLETTER);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_MESSAGE);
        onCreate(db);
    }
}
